package com.authine.cloudpivot.ext.applicationservice;

import com.alibaba.cola.dto.SingleResponse;
import com.authine.cloudpivot.ext.applicationservice.base.ApplicationBaseService;
import com.authine.cloudpivot.ext.dto.transfer.ResaleInvoiceDto;
import com.authine.cloudpivot.ext.dto.transfer.TransferOrderDto;
import com.authine.cloudpivot.ext.service.PurchaseSaleService;
import com.authine.cloudpivot.ext.service.impl.PurchaseSaleServiceImpl;
import com.authine.cloudpivot.ext.utils.StringUtils;
import com.authine.mvp.app.launcher.domain.utills.ApplicationContextUtils;
import com.authine.mvp.app.launcher.dto.bo.response.BO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

import javax.ws.rs.POST;
import javax.ws.rs.Path;

import static com.authine.hermes.app.launcher.service.ApplicationServiceFoundation.CUSTOM_SERVICE;

/**
 * @ClassName TransferManageOrderService
 * @Description: 转售管理自定义服务
 * @Author cjj
 * @Date 2021/6/18
 * @Version V1.0
 **/
@Path("PurchaseSaleManageService")
@Slf4j
public class PurchaseSaleManageService extends ApplicationBaseService {
    private PurchaseSaleService purchaseSaleService = new PurchaseSaleServiceImpl();
    private NamedParameterJdbcTemplate jdbcTemplate = ApplicationContextUtils.getBean(NamedParameterJdbcTemplate.class);

    /**
     * 转售管理-入库订单商品-提交出库订单
     *
     * @param dto
     * @return
     */
    @Path("submitOutputOrder")
    @POST
    @Operation(summary = "转售管理-入库订单商品-提交出库订单", tags = CUSTOM_SERVICE, description = "dto、dto.transferOrderGoods必填")
    public SingleResponse<BO> submitOutputOrder(@Parameter TransferOrderDto dto) {
        if (null == dto || dto.getTransferOrderGoods().isEmpty()) {
            return SingleResponse.buildFailure("-1", "订单信息不能为空");
        }
        return purchaseSaleService.saveOutputOrder(dto);
    }

    /**
     * 转售管理-申请开票
     *
     * @param dto
     * @return
     */
    @Path("saveInvoice")
    @POST
    @Operation(summary = "转售管理-申请开票-保存发票申请单", tags = CUSTOM_SERVICE, description = "dto、dto.resaleInvoiceDetails必填")
    public SingleResponse<BO> saveInvoice(@Parameter ResaleInvoiceDto dto) {
        if (null == dto || dto.getResaleInvoiceDetails().isEmpty()) {
            return SingleResponse.buildFailure("-1", "发票信息不完整");
        }
        return purchaseSaleService.saveResaleInvoice(dto);
    }

    /**
     * 转售管理-确认开票
     *
     * @param dto
     * @return
     */
    @Path("confirmInvoice")
    @POST
    @Operation(summary = "转售管理-确认开票", tags = CUSTOM_SERVICE, description = "id、date、code、number、drawer必填")
    public SingleResponse<BO> confirmInvoice(@Parameter ResaleInvoiceDto dto) {
        if (StringUtils.isBlank(dto.getId())) {
            return SingleResponse.buildFailure("-1", "转售发票ID必填");
        }
        return purchaseSaleService.confirmResaleInvoice(dto);
    }
}
